//
//  SendFormViewController.m
//  Roskildeapp
//
//  Created by My Name on 11/21/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "SendFormViewController.h"

@implementation SendFormViewController
@synthesize SendSMSButton;
@synthesize managedObjectContext,fetchedResultsController,dateFormatter;

- (id)initWithManagedObjectContext:(NSManagedObjectContext*)objectContext
{
    self = [super init];
    if (self) {
        self.managedObjectContext = objectContext;
        self.title = @"Send Current Location";
        
        UIImage *tabImage = [[UIImage imageNamed:@"tabIconNew.png"] autorelease];
        self.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Send Current Location" image:tabImage tag:0];
    }
    return self;
}

- (IBAction)SendSMSButtonClicked:(id)sender {
    
    MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
	if([MFMessageComposeViewController canSendText])
	{
		controller.body = @"Hi! I am using this awesome iPhone app to track the locations of my friends at Roskilde Festival: 'AppStoreLink' If you have the app, you can see my location here: 'LocationLink'.";		controller.recipients = [NSArray arrayWithObjects:nil];
		controller.messageComposeDelegate = self;
		[self presentModalViewController:controller animated:YES];
	}	
}

/*
#pragma mark -
#pragma mark Dismiss Mail/SMS view controller

// Dismisses the message composition interface when users tap Cancel or Send. Proceeds to update the 
// feedback message field with the result of the operation.
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller 
				 didFinishWithResult:(MessageComposeResult)result {
	
	
	//feedbackMsg.hidden = NO;
	// Notifies users about errors associated with the interface
	switch (result)
	{
		case MessageComposeResultCancelled:
			feedbackMsg.text = @"Result: SMS sending canceled";
			break;
		case MessageComposeResultSent:
			feedbackMsg.text = @"Result: SMS sent";
			break;
		case MessageComposeResultFailed:
			feedbackMsg.text = @"Result: SMS sending failed";
			break;
		default:
			feedbackMsg.text = @"Result: SMS not sent";
			break;
	}
	[self dismissModalViewControllerAnimated:YES];
}
*/

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    [self.navigationController.navigationBar setTintColor:[UIColor blackColor]];
    
}

- (void)viewDidUnload
{
    [self setSendSMSButton:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)dealloc {
    [dateFormatter release];
    [SendSMSButton release];
    [super dealloc];
}

/*
 Credits: Erik B, coryjacobsen
 Source: stackoverflow.com/questions/599405/iphone-navigation-bar-title-text-color
 */
-(void)setTitle:(NSString *)title{
    [super setTitle:title];
    UILabel *titleView = (UILabel *)self.navigationItem.titleView;
    if(!titleView){
        titleView = [[UILabel alloc] initWithFrame:CGRectMake(0,0, [self.title sizeWithFont:[UIFont fontWithName:@"Courier-BoldOblique" size:17.0]].width, 44)];
        titleView.backgroundColor = [UIColor clearColor];
        titleView.font = [UIFont fontWithName:@"Courier-BoldOblique" size:17.0];
        titleView.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
        
        titleView.textColor = [UIColor colorWithRed:0xFF/255.0f green:0x90/255.0f blue:0x00/255.0f alpha:1];
        
        self.navigationItem.titleView = titleView;
        [titleView release];
    }
    titleView.text = title;
    [titleView sizeToFit];
}

@end
